package com.example.tourpal.widget;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.tourpal.R;

public class SpotGalleryItem extends LinearLayout {

	private TextView galleryName;
	private TextView galleryDate;

	public SpotGalleryItem(Context context) {
		this(context, null);
		// TODO Auto-generated constructor stub
	}

	public SpotGalleryItem(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
		// TODO Auto-generated constructor stub
	}

	public SpotGalleryItem(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);

		setOrientation(LinearLayout.VERTICAL);
		setGravity(Gravity.CENTER);
		setPadding(8, 16, 8, 8);

		galleryName = new TextView(context);
		galleryName.setGravity(Gravity.CENTER);
		galleryName.setTextColor(Color.WHITE);
		galleryName.setMaxEms(2);
		galleryName.setMaxLines(1);
		galleryDate = new TextView(context);
		galleryDate.setGravity(Gravity.CENTER);

		setGalleryItem(false, false);

		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

		addView(galleryName, params);
		addView(galleryDate, params);
	}

	public TextView getGalleryName() {
		return galleryName;
	}

	public void setGalleryItem(boolean isCurrent, boolean isRecruit) {
		int bgRes = 0;
		if (isCurrent) {
			bgRes = R.drawable.spot_passed;
		} else {
			bgRes = R.drawable.spot_idle;
		}
		galleryName.setBackgroundResource(bgRes);

		Drawable flag = null;
		if (isRecruit) {
			flag = getResources().getDrawable(R.drawable.recruit_sign_small);
			flag.setBounds(0, 0, flag.getMinimumWidth(),
					flag.getMinimumHeight());
		}
		galleryDate.setCompoundDrawables(null, null, flag, null);
	}

	public TextView getGalleryDate() {
		return galleryDate;
	}

}
